#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5 + 10;

vector<ll> a;
ll n;

void init() {
    for (int i = 1; i <= 17; i++) {
        for (int j = 1; j <= 9; j++) {
            for (int d = -9; d <= 9; d++) {
                ll num = j;

                ll start = j;
                bool flag = true;
                for (int k = 2; k <= i; k++) {
                    start += d;
                    if (start >= 0 && start <= 9) {
                        num = num * 10 + start;
                    } else {
                        flag = false;
                        break;
                    }
                }

                if (flag) a.push_back(num);
            }
        }
    }
    a.push_back(111111111111111111);
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    init();
    cin >> n;

    int l = 0, r = a.size() - 1;
    while(l < r) {
        int mid = (l+r)>>1;
        if (a[mid] >= n) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << a[l] << endl;
    return 0;
}
